;(function() {
		init_parsley();
		$.fn.modal.Constructor.prototype.enforceFocus = function () { };
		 $('#cabinet_id').select2({  
		        placeholder: "请输入柜号",  
  		});  
	    $('#member_id').select2({
		    placeholder: "请输入会员姓名/手机号",
		    minimumInputLength: 2,
		    ajax:{
		        delay:1000,
		        url:"/gym/GymCabinetSubscribe/ajax_member_data",
		        data:function(params){
		            var query = {
		                search: params.term,
		                page: params.page || 1
		            };
		            return query;
		        },
		        processResults: function (data, params) {
		            params.page = params.page || 1;
		            return {
		                results: data.results,
		                pagination: {
		                    more: data.more
		                }
		            };
		        },
		    }
	    })
		$('.datepicker').datepicker({format: 'yyyy-mm-dd',todayHighlight:true,clearBtn:true,autoclose:true , language:"zh-CN"});
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			loading();
	   			$.post(
	   				"/gym/GymCabinetSubscribe/add_post",
	   				$("#validate-form").serialize(),
	   				function(data){
	   					close_loading();
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("操作成功！", ''); 
			      			$("#myform #btn-advanced-refresh").trigger("click");// 刷新页面
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
	   	
})();